<?php
	include("../include/config.php");
	include("../include/functions.php");
	
	if($_GET['table']){
		mysqli_query($db_connect, "DELETE FROM `cns_projects` WHERE id = '$_GET[id]'");
	
		header("location:../admin.php?data=projects&msg=delete");
	}
	if(isset($_POST['page_id']) && $_POST['page_id']==''){
			$pr_id=array_shift($_POST);
			$pr_img=array_shift($_POST);
			$_POST['name']=htmlspecialchars(str_replace("'","",$_POST['page_title']));
			
			
			$_POST['created_date']=date("Y-m-d H:i:s");
			
			$_POST['updated_date']=date("Y-m-d H:i:s");
			
			if($_FILES['images']['name']){
				 $image_file=rand().$_FILES['images']['name'];
				$image_path='../../images/'.$image_file;
				$temp=$_FILES['images']['tmp_name'];
				copy($temp,$image_path);
				$_POST['image']=$image_file;
			}
			
			$_POST['desc']=htmlspecialchars(str_replace("'","",$_POST['page_description']));			$sel = mysqli_query($db_connect, "INSERT INTO `cns_projects`(`name`, `desc`, `image`, `created_date`, `updated_date`)				VALUES ('$_POST[name]','$_POST[desc]','$_POST[image]','$_POST[created_date]','$_POST[updated_date]')");
			//db_insert(DB_PREFIX.'pages',$_POST);
			
			header('location:../admin.php?data=projects&msg=success');
			
	}else{
		$product_id=array_shift($_POST);
			$images=array_shift($_POST);
		
			$_POST['name']=str_replace("'","",$_POST['page_title']);
		
				if($_FILES['images']['name']){
					 $image_file=rand().$_FILES['images']['name'];
					$image_path='../../images/'.$image_file;
					$temp=$_FILES['images']['tmp_name'];
					copy($temp,$image_path);
					$_POST['image']=$image_file;
				}
				else{
					$_POST['image']=$images;
				}
						$_POST['updated_date']=date("Y-m-d H:i:s");
			
			$_POST['desc']=htmlspecialchars(str_replace("'","",$_POST['page_description']));						$sel= mysqli_query($db_connect, "UPDATE `cns_projects` SET `name`='$_POST[name]',`desc`='$_POST[desc]',`image`='$_POST[image]',			`updated_date`='$_POST[updated_date]' WHERE id='$product_id'");
			
			//db_update(DB_PREFIX.'pages',$_POST,array('page_id'=>$product_id));
			
			header('location:../admin.php?data=projects&msg=updated');
	}
	
?>